package com.ruoyi.info.service.impl;

import java.util.List;
import java.util.Date;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.info.mapper.SysInfoArticleMapper;
import com.ruoyi.info.domain.SysInfoArticle;
import com.ruoyi.info.service.ISysInfoArticleService;

/**
 * 资讯文章Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-27
 */
@Service
public class SysInfoArticleServiceImpl implements ISysInfoArticleService 
{
    @Autowired
    private SysInfoArticleMapper sysInfoArticleMapper;

    /**
     * 查询资讯文章
     * 
     * @param articleId 资讯文章主键
     * @return 资讯文章
     */
    @Override
    public SysInfoArticle selectSysInfoArticleByArticleId(Long articleId)
    {
        return sysInfoArticleMapper.selectSysInfoArticleByArticleId(articleId);
    }

    /**
     * 查询资讯文章列表
     * 
     * @param sysInfoArticle 资讯文章
     * @return 资讯文章
     */
    @Override
    public List<SysInfoArticle> selectSysInfoArticleList(SysInfoArticle sysInfoArticle)
    {
        return sysInfoArticleMapper.selectSysInfoArticleList(sysInfoArticle);
    }

    /**
     * 新增资讯文章
     * 
     * @param sysInfoArticle 资讯文章
     * @return 结果
     */
    @Override
    public int insertSysInfoArticle(SysInfoArticle sysInfoArticle)
    {
        sysInfoArticle.setCreateTime(DateUtils.getNowDate());
        if ("1".equals(sysInfoArticle.getStatus())) {
            sysInfoArticle.setPublishTime(DateUtils.getNowDate());
        }
        return sysInfoArticleMapper.insertSysInfoArticle(sysInfoArticle);
    }

    /**
     * 修改资讯文章
     * 
     * @param sysInfoArticle 资讯文章
     * @return 结果
     */
    @Override
    public int updateSysInfoArticle(SysInfoArticle sysInfoArticle)
    {
        sysInfoArticle.setUpdateTime(DateUtils.getNowDate());
        if ("1".equals(sysInfoArticle.getStatus()) && sysInfoArticle.getPublishTime() == null) {
            sysInfoArticle.setPublishTime(DateUtils.getNowDate());
        }
        return sysInfoArticleMapper.updateSysInfoArticle(sysInfoArticle);
    }

    /**
     * 批量删除资讯文章
     * 
     * @param articleIds 需要删除的资讯文章主键
     * @return 结果
     */
    @Override
    public int deleteSysInfoArticleByArticleIds(Long[] articleIds)
    {
        return sysInfoArticleMapper.deleteSysInfoArticleByArticleIds(articleIds);
    }

    /**
     * 删除资讯文章信息
     * 
     * @param articleId 资讯文章主键
     * @return 结果
     */
    @Override
    public int deleteSysInfoArticleByArticleId(Long articleId)
    {
        return sysInfoArticleMapper.deleteSysInfoArticleByArticleId(articleId);
    }

    /**
     * 更新文章浏览次数
     * 
     * @param articleId 文章ID
     * @return 结果
     */
    @Override
    public int updateViewCount(Long articleId)
    {
        return sysInfoArticleMapper.updateViewCount(articleId);
    }

    /**
     * 查询推荐文章列表
     * 
     * @param limit 限制数量
     * @return 文章列表
     */
    @Override
    public List<SysInfoArticle> selectRecommendArticleList(int limit)
    {
        return sysInfoArticleMapper.selectRecommendArticleList(limit);
    }

    /**
     * 查询置顶文章列表
     * 
     * @return 文章列表
     */
    @Override
    public List<SysInfoArticle> selectTopArticleList()
    {
        return sysInfoArticleMapper.selectTopArticleList();
    }

    /**
     * 发布文章
     * 
     * @param articleId 文章ID
     * @return 结果
     */
    @Override
    public int publishArticle(Long articleId)
    {
        SysInfoArticle article = new SysInfoArticle();
        article.setArticleId(articleId);
        article.setStatus("1");
        article.setPublishTime(DateUtils.getNowDate());
        return sysInfoArticleMapper.updateSysInfoArticle(article);
    }

    /**
     * 下架文章
     * 
     * @param articleId 文章ID
     * @return 结果
     */
    @Override
    public int unpublishArticle(Long articleId)
    {
        SysInfoArticle article = new SysInfoArticle();
        article.setArticleId(articleId);
        article.setStatus("2");
        return sysInfoArticleMapper.updateSysInfoArticle(article);
    }
}
